<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="车辆名称" prop="vehicleName">
                <el-input v-model="queryParams.vehicleName" placeholder="请输入车辆名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="车牌号" prop="plateNumber">
                <el-input v-model="queryParams.plateNumber" placeholder="请输入车牌号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="客户名称" prop="customerName">
                <el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="定损状态" prop="damageStatus">
                <el-select v-model="queryParams.damageStatus" clearable placeholder="请选择">
                    <el-option v-for="item in damageOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="发票状态" prop="invoiceStatus">
                <el-select v-model="queryParams.invoiceStatus" clearable placeholder="请选择">
                    <el-option v-for="item in invoiceOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row>
            <el-col :span="8" v-for="(item, index) in workOrderList" :key="index">
                <el-card :body-style="{ padding: '0px' }">
                    <!-- <el-carousel>
                        <el-carousel-item v-for="(url, index) in item.image.split(',')" :key="index">
                            <el-image :src="url" fit="scale-down" />
                        </el-carousel-item>
                    </el-carousel> -->

                    <el-image v-if="item.image != null && item.image != ''" :src="item.image.split(',')[0]"
                        style="width: 548.98px; height: 308.8px;" :preview-src-list="item.image.split(',')" />
                    <el-image v-else style="width: 548.98px; height: 308.8px;"></el-image>
                    <div style="height: 60px; padding-top: 20px; padding-bottom: 10px; justify-content: center; background: linear-gradient(to left, pink, skyblue); 
                    font-size: 18px; font-weight: bold;">
                        <span style="padding-left: 10px;">车辆名称：{{ item.vehicleName }}</span>
                        <span style="float: right; padding-right: 10px;">车牌号：{{ item.plateNumber }}</span>
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import { listWorkOrder } from "@/api/workOrder"
import ImagePreview from "@/components/ImagePreview"
import Pagination from "@/components/Pagination"
import ImageUpload from "@/components/ImageUpload"

export default {
    name: "WorkOrderView",
    components: {
        ImagePreview,
        Pagination,
        ImageUpload
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 物品表格数据
            workOrderList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                totalRow: -1,
                vehicleName: null,
                plateNumber: null,
                customerName: null,
                damageStatus: null,
                invoiceStatus: null
            },
            damageOptions: [{ label: '未定损', value: 0 }, { label: '已定损', value: 1 }],
            invoiceOptions: [{ label: '未开发票', value: 0 }, { label: '已开发票', value: 1 }],
            // unitOptions: [{ label: '年', key: 1 }, { label: '月', key: 2 }, { label: '日', key: 3 }],
            // 表单参数
            form: {},
            // uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload",
            // fileList: [],
            // 表单校验
            rules: {
                vehicleName: [
                    { required: true, message: "车辆名称不能为空", trigger: "blur" }
                ],
                plateNumber: [
                    { required: true, message: "车牌号不能为空", trigger: "blur" }
                ]
            }
        }
    },
    created() {
        this.getList()
    },
    methods: {
        /** 查询物品列表 */
        getList() {
            this.loading = true
            listWorkOrder(this.queryParams).then(response => {
                this.workOrderList = response.data.records
                this.total = response.data.totalRow
                this.queryParams.totalRow = response.data.totalRow
                this.loading = false
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                vehicleName: null,
                plateNumber: null,
                duty: null,
                customerName: null,
                image: null,
                damageStatus: 0,
                damageStaff: null,
                damageAmount: null,
                invoiceStatus: 0,
                rescueAmount: null,
                receiveAmount: null
            }
            // this.fileList = []
            // this.resetForm("form")

        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.queryParams.totalRow = -1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.$refs["queryForm"].resetFields();
            this.handleQuery()
        },
        /** 导出按钮操作 */
        // handleExport() {
        //   this.download('flex/item/export', {
        //     ...this.queryParams
        //   }, `item_${new Date().getTime()}.xlsx`)
        // }
    }
}
</script>